// 主函数
function hanoi1(n) {
  leftToRight(n)
}

function leftToRight(n) {
  if(n == 1) {
    console.log('move 1 form left to right')
    return
  }
  leftToMid(n-1)
  console.log(`move ${n} from left to right`)
  midToRight(n-1)
}
function leftToMid(n) {
  if(n ==  1) {
    console.log('move 1 form left to mid')
    return
  }
  leftToRight(n-1)
  console.log('move' + n + 'from left to mid')
  rightToMid(n-1)
}

function midToRight(n) {
  if(n ==  1) {
    console.log('move 1 form mid to right')
    return
  }
  midToLeft(n-1)
  console.log('move' + n + 'from mid to right')
  leftToRight(n-1)
}

function midToLeft(n) {
  if(n ==  1) {
    console.log('move 1 form mid to left')
    return
  }
  midToRight(n-1)
  console.log('move ' + n + 'from mid to left')
  rightToleft(n-1)
}

function rightToMid(n) {
  if(n ==  1) {
    console.log('move 1 form right to mid')
    return
  }
  rightToleft(n-1)
  console.log('move ' + n + 'from right to mid')
  leftToMid(n-1)
}
function rightToleft(n) {
  if(n ==  1) {
    console.log('move 1 form right to left')
    return
  }
  rightToMid(n-1)
  console.log('move ' + n + 'from right to left')
  midToLeft(n-1)
}

hanoi1(3)



